package com.chinamobile.maps.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.chinamobile.maps.dao.IGridDAO;
import com.chinamobile.maps.orm.Grid;
import com.chinamobile.maps.orm.Regions;

/**
 * @ClassName:   GridDAOImpl
 * @Description: TODO
 * @author:      frankwong
 * @date:        2012-10-28 下午9:49:27
 *
 */
public class GridDAOImpl extends HibernateDaoSupport implements IGridDAO {

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IGridDAO#addGrid(com.chinamobile.maps.orm.Grid)
	 */
	@Override
	public void addGrid(Grid grid) {
		this.getHibernateTemplate().save(grid);

	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IGridDAO#delGrid(com.chinamobile.maps.orm.Grid)
	 */
	@Override
	public void delGrid(Grid grid) {
		this.getHibernateTemplate().delete(grid);

	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IGridDAO#delGrid(int)
	 */
	@Override
	public void delGrid(int id) {
		this.getHibernateTemplate().delete(getGridById(id));

	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IGridDAO#updateGrid(com.chinamobile.maps.orm.Grid)
	 */
	@Override
	public void updateGrid(Grid grid) {
		this.getHibernateTemplate().update(grid);

	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IGridDAO#getGrid()
	 */
	@Override
	public List<Grid> getGrid() {
		List list = this.getHibernateTemplate().find("from Grid");
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IGridDAO#getGridById(int)
	 */
	@Override
	public Grid getGridById(int id) {
		List list = this.getHibernateTemplate().find("from Grid as g where g.id=?",
				new Object[] { id });

		if (list != null && list.size() > 0) {
			return (Grid) list.get(0);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IGridDAO#getObjects(java.lang.String)
	 */
	@Override
	public List<Grid> getObjects(String hsql) {
		List list = this.getHibernateTemplate().find(hsql);
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}

	@Override
	public Grid getGridByname(String name) {
		List list = this.getHibernateTemplate().find("from Grid as g where g.name=?",
				new Object[] { name });

		if (list != null && list.size() > 0) {
			return (Grid) list.get(0);
		}
		return null;
	}

}
